<?php
namespace BP\Sys;
require_once("BP/En/Map.php");
class SysDocFile extends EntityMyPK {
	public function getEnName () 
	{
		return $this->GetValStringByKey(SysDocFileAttr::$EnName);
	}
	public function setEnName ($value) // [String value]
	{
		$this->SetValByKey(SysDocFileAttr::$EnName, $value);
	}
	public function getRefKey () 
	{
		return $this->GetValStringByKey(SysDocFileAttr::$RefKey);
	}
	public function setRefKey ($value) // [String value]
	{
		$this->SetValByKey(SysDocFileAttr::$RefKey, $value);
	}
	public function getRefVal () 
	{
		return $this->GetValStringByKey(SysDocFileAttr::$RefVal);
	}
	public function setRefVal ($value) // [String value]
	{
		$this->SetValByKey(SysDocFileAttr::$RefVal, $value);
	}
	public function getFileName () 
	{
		return $this->GetValStringByKey(SysDocFileAttr::$FileName);
	}
	public function setFileName ($value) // [String value]
	{
		$this->SetValByKey(SysDocFileAttr::$FileName, $value);
	}
	public function getFileSize () 
	{
		return $this->GetValIntByKey(SysDocFileAttr::$FileSize);
	}
	public function setFileSize ($value) // [int value]
	{
		$this->SetValByKey(SysDocFileAttr::$FileSize, $value);
	}
	public function getFileType () 
	{
		return $this->GetValStringByKey(SysDocFileAttr::$FileType);
	}
	public function setFileType ($value) // [String value]
	{
		$this->SetValByKey(SysDocFileAttr::$FileType, $value);
	}
	public function getDocHtml () 
	{
		return $DataType->ParseText2Html($this->getDocText());
	}
	public function getDocText1 () 
	{
		return "";
	}
	public function getDocText () 
	{
		return ((((((((((((((((((($this->getD1() . $this->getD2()) . $this->getD3()) . $this->getD4()) . $this->getD5()) . $this->getD6()) . $this->getD7()) . $this->getD8()) . $this->getD9()) . $this->getD10()) . $this->getD11()) . $this->getD12()) . $this->getD13()) . $this->getD14()) . $this->getD15()) . $this->getD16()) . $this->getD17()) . $this->getD18()) . $this->getD19()) . $this->getD20());
	}
	public function setDocText ($value) // [String value]
	{
		$len = $value->length();
		$this->setFileSize($len);
		$step = 2000;
		$i = 0;
		$idx = -1;
		while ( TRUE ) 
		{
			++$i;
			++$idx;
			if (($len > ($step * $i)))
			{
				$this->SetValByKey(("D" . $i), $value->substring(($step * $idx), (($step * $idx) + $step)));
			}
			else
			{
				$this->SetValByKey(("D" . $i), $value->substring(($step * $idx)));
				break;
			}
			if (($i > 20))
			{
				throw new \RuntimeException("数据太大存储不下�?");
			}
		}
	}
	public function getD1 () 
	{
		return $this->GetValStrByKey("D1");
	}
	public function setD1 ($value) // [String value]
	{
		$this->SetValByKey("D1", $value);
	}
	public function getD2 () 
	{
		return $this->GetValStrByKey("D2");
	}
	public function setD2 ($value) // [String value]
	{
		$this->SetValByKey("D2", $value);
	}
	public function getD3 () 
	{
		return $this->GetValStrByKey("D3");
	}
	public function setD3 ($value) // [String value]
	{
		$this->SetValByKey("D3", $value);
	}
	public function getD4 () 
	{
		return $this->GetValStrByKey("D4");
	}
	public function setD4 ($value) // [String value]
	{
		$this->SetValByKey("D4", $value);
	}
	public function getD5 () 
	{
		return $this->GetValStrByKey("D5");
	}
	public function setD5 ($value) // [String value]
	{
		$this->SetValByKey("D5", $value);
	}
	public function getD6 () 
	{
		return $this->GetValStrByKey("D6");
	}
	public function setD6 ($value) // [String value]
	{
		$this->SetValByKey("D6", $value);
	}
	public function getD7 () 
	{
		return $this->GetValStrByKey("D7");
	}
	public function setD7 ($value) // [String value]
	{
		$this->SetValByKey("D7", $value);
	}
	public function getD8 () 
	{
		return $this->GetValStrByKey("D8");
	}
	public function setD8 ($value) // [String value]
	{
		$this->SetValByKey("D8", $value);
	}
	public function getD9 () 
	{
		return $this->GetValStrByKey("D9");
	}
	public function setD9 ($value) // [String value]
	{
		$this->SetValByKey("D9", $value);
	}
	public function getD10 () 
	{
		return $this->GetValStrByKey("D10");
	}
	public function setD10 ($value) // [String value]
	{
		$this->SetValByKey("D10", $value);
	}
	public function getD11 () 
	{
		return $this->GetValStrByKey("D11");
	}
	public function setD11 ($value) // [String value]
	{
		$this->SetValByKey("D11", $value);
	}
	public function getD12 () 
	{
		return $this->GetValStrByKey("D12");
	}
	public function setD12 ($value) // [String value]
	{
		$this->SetValByKey("D12", $value);
	}
	public function getD13 () 
	{
		return $this->GetValStrByKey("D13");
	}
	public function setD13 ($value) // [String value]
	{
		$this->SetValByKey("D13", $value);
	}
	public function getD14 () 
	{
		return $this->GetValStrByKey("D14");
	}
	public function setD14 ($value) // [String value]
	{
		$this->SetValByKey("D14", $value);
	}
	public function getD15 () 
	{
		return $this->GetValStrByKey("D15");
	}
	public function setD15 ($value) // [String value]
	{
		$this->SetValByKey("D15", $value);
	}
	public function getD16 () 
	{
		return $this->GetValStrByKey("D16");
	}
	public function setD16 ($value) // [String value]
	{
		$this->SetValByKey("D16", $value);
	}
	public function getD17 () 
	{
		return $this->GetValStrByKey("D17");
	}
	public function setD17 ($value) // [String value]
	{
		$this->SetValByKey("D17", $value);
	}
	public function getD18 () 
	{
		return $this->GetValStrByKey("D18");
	}
	public function setD18 ($value) // [String value]
	{
		$this->SetValByKey("D18", $value);
	}
	public function getD19 () 
	{
		return $this->GetValStrByKey("D19");
	}
	public function setD19 ($value) // [String value]
	{
		$this->SetValByKey("D19", $value);
	}
	public function getD20 () 
	{
		return $this->GetValStrByKey("D20");
	}
	public function setD20 ($value) // [String value]
	{
		$this->SetValByKey("D20", $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($pk) // [String pk]
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String_String_String ($enName, $key, $val) // [String enName, String key, String val]
	{
		$me = new self();
		$me->setMyPK((((($enName . "@") . $key) . "@") . $val));
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("Sys_DocFile", "备注字段文件管理�?");
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->AddMyPK();
		$map->AddTBString(SysDocFileAttr::$FileName, NULL, "名称",  FALSE ,  TRUE , 0, 200, 30);
		$map->AddTBInt(SysDocFileAttr::$FileSize, 0, "大小",  TRUE ,  TRUE );
		$map->AddTBString(SysDocFileAttr::$FileType, NULL, "文件类型",  TRUE ,  TRUE , 0, 50, 20);
		$map->AddTBString("D1", NULL, "D1",  TRUE ,  TRUE , 0, 4000, 20);
		$map->AddTBString("D2", NULL, "D2",  TRUE ,  TRUE , 0, 4000, 20);
		$map->AddTBString("D3", NULL, "D3",  TRUE ,  TRUE , 0, 4000, 20);
		if ((($map->getEnDBUrl()->getDBType() == $DBType->Oracle) || ($map->getEnDBUrl()->getDBType() == $DBType->MSSQL)))
		{
			$map->AddTBString("D4", NULL, "D4",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D5", NULL, "D5",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D6", NULL, "D6",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D7", NULL, "D7",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D8", NULL, "D8",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D9", NULL, "D9",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D10", NULL, "D10",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D11", NULL, "D11",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D12", NULL, "D12",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D13", NULL, "D13",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D14", NULL, "D14",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D15", NULL, "D15",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D16", NULL, "D16",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D17", NULL, "D17",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D18", NULL, "D18",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D19", NULL, "D19",  TRUE ,  TRUE , 0, 4000, 20);
			$map->AddTBString("D20", NULL, "D20",  TRUE ,  TRUE , 0, 4000, 20);
		}
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	public static function GetValHtmlV2 ($enName, $pkVal) // [String enName, String pkVal]
	{
		try 
		{
			returnDataType->ReadTextFile(((((SystemConfig::getPathOfFDB() . $enName) . "\\") . $pkVal) . ".fdb"));
		}
		catch (\Exception $e)
		{
			return NULL;
		}
	}
	public static function GetValTextV2 ($enName, $pkVal) // [String enName, String pkVal]
	{
		try 
		{
			returnDataType->ReadTextFile(((((SystemConfig::getPathOfFDB() . $enName) . "\\") . $pkVal) . ".fdb"));
		}
		catch (\Exception $e)
		{
			return NULL;
		}
	}
	public static function SetValV2 ($enName, $pkVal, $val) // [String enName, String pkVal, String val]
	{
		try 
		{
			$dir = ((SystemConfig::getPathOfFDB() . $enName) . "\\");
			if (((new File($dir))->isDirectory() ==  FALSE ))
			{
				(new File($dir))->mkdirs();
			}
			DataType->SaveAsFile(((($dir . "\\") . $pkVal) . ".fdb"), $val);
		}
		catch (\RuntimeException $ex)
		{
			throw $ex;
		}
	}
	public static function GetValHtmlV1 ($enName, $pkVal) // [String enName, String pkVal]
	{
		$sdf = SysDocFile::constructor__();
		$sdf->setMyPK((($enName . "@Doc@") . $pkVal));
		$sdf->RetrieveFromDBSources();
		return $sdf->getDocHtml();
	}
	public static function GetValTextV1 ($enName, $pkVal) // [String enName, String pkVal]
	{
		$sdf = SysDocFile::constructor__();
		$sdf->setMyPK((($enName . "@Doc@") . $pkVal));
		$sdf->RetrieveFromDBSources();
		return $sdf->getDocText();
	}
	public static function SetValV1 ($enName, $pkVal, $val) // [String enName, String pkVal, String val]
	{
		$sdf = SysDocFile::constructor__();
		$sdf->setMyPK((($enName . "@Doc@") . $pkVal));
		$sdf->setFileSize($val->length());
		$sdf->setDocText($val);
		$sdf->Save();
	}
	abstract function UpdateLoadFileOfAccess ($FileName); // [String FileName]
}
?>
